import java.util.HashMap;
import java.util.HashSet;

/*
class Solution {
    public int lengthOfLongestSubstring(String s) {
        HashSet<Character> set = new HashSet<>();
        char[] strArr = s.toCharArray();
        int left = 0;
        int right = 0;
        int maxLen = Integer.MIN_VALUE;
        for (; right < strArr.length; right++) {
            if (!set.contains(strArr[right])) {
                set.add(strArr[right]);
                maxLen = Math.max(maxLen, set.size());
            }else {
                while (strArr[left] != strArr[right]) {
                    set.remove(strArr[left]);
                    left++;
                }
                left++;
            }//
        }
        return maxLen;
    }
}*/

class Solution {
    public int lengthOfLongestSubstring(String ss) {
        char[] s = ss.toCharArray();
        int left = 0;
        int right = 0;
        int len = 0;
        int[] hash = new int[128];
        for (; right < ss.length(); right++) {
            hash[s[right]]++;
            while (hash[s[right]] == 2) {
                hash[s[left]]--;
                left++;
            }
            len = Math.max(len, right - left + 1);
        }
        return len;
    }
}
